/**
 * 
 */

/**
 * @author antonio081014
 * @since Feb 9, 2012, 8:09:45 AM
 */
import java.util.ArrayList;
import java.util.List;

public class DengklekMakingChains {
    public int maxBeauty(String[] chains) {
        int N = chains.length;
        List<String> newChain = new ArrayList<String>();
        int count = 0;
        for (int i = 0; i < chains.length; i++) {
            if (chains[i].contains(".") == false) {
                count += chains[i].charAt(0) - '0';
                count += chains[i].charAt(1) - '0';
                count += chains[i].charAt(2) - '0';
            }
            else {
                newChain.add(chains[i]);
            }
        }
        int max = 0;
        int max2 = 0;
        for (int i = 0; i < newChain.size(); i++) {
            int tmp = 0;
            for (int k = 2; k >= 0; k--)
                if (newChain.get(i).charAt(k) != '.')
                    tmp += newChain.get(i).charAt(k) - '0';
                else
                    break;
            int tmp3 = 0;
            for (int k = 0; k < 3; k++)
                if (newChain.get(i).charAt(k) != '.')
                    tmp3 += newChain.get(i).charAt(k) - '0';
                else
                    break;
            max2 = Math.max(max2, newChain.get(i).charAt(1) - '0');
            max = Math.max(max, tmp);
            max = Math.max(max, tmp3);
            for (int j = 0; j < newChain.size(); j++) {
                if (i != j) {
                    int tmp2 = 0;
                    for (int k = 0; k <= 2; k++)
                        if (newChain.get(j).charAt(k) != '.')
                            tmp2 += newChain.get(j).charAt(k) - '0';
                        else
                            break;
                    max = Math.max(max, tmp + tmp2);
                }
            }
        }
        return Math.max(count + max, max2);
    }

     public static void main(String[] args)
	{
		long time;
		int answer;
		boolean errors = false;
		int desiredAnswer;
		
		
		time = System.currentTimeMillis();
		answer = new DengklekMakingChains().maxBeauty(new String[]{".15", "7..", "402", "..3"});
		System.out.println("Time: " + (System.currentTimeMillis()-time)/1000.0 + " seconds");
		desiredAnswer = 19;
		System.out.println("Your answer:");
		System.out.println("\t" + answer);
		System.out.println("Desired answer:");
		System.out.println("\t" + desiredAnswer);
		if (answer != desiredAnswer)
		{
			errors = true;
			System.out.println("DOESN'T MATCH!!!!");
		}
		else
			System.out.println("Match :-)");
		System.out.println();
		time = System.currentTimeMillis();
		answer = new DengklekMakingChains().maxBeauty(new String[]{"..1", "7..", "567", "24.", "8..", "234"});
		System.out.println("Time: " + (System.currentTimeMillis()-time)/1000.0 + " seconds");
		desiredAnswer = 36;
		System.out.println("Your answer:");
		System.out.println("\t" + answer);
		System.out.println("Desired answer:");
		System.out.println("\t" + desiredAnswer);
		if (answer != desiredAnswer)
		{
			errors = true;
			System.out.println("DOESN'T MATCH!!!!");
		}
		else
			System.out.println("Match :-)");
		System.out.println();
		time = System.currentTimeMillis();
		answer = new DengklekMakingChains().maxBeauty(new String[]{"...", "..."});
		System.out.println("Time: " + (System.currentTimeMillis()-time)/1000.0 + " seconds");
		desiredAnswer = 0;
		System.out.println("Your answer:");
		System.out.println("\t" + answer);
		System.out.println("Desired answer:");
		System.out.println("\t" + desiredAnswer);
		if (answer != desiredAnswer)
		{
			errors = true;
			System.out.println("DOESN'T MATCH!!!!");
		}
		else
			System.out.println("Match :-)");
		System.out.println();
		time = System.currentTimeMillis();
		answer = new DengklekMakingChains().maxBeauty(new String[]{"16.", "9.8", ".24", "52.", "3.1", "532", "4.4", "111"});
		System.out.println("Time: " + (System.currentTimeMillis()-time)/1000.0 + " seconds");
		desiredAnswer = 28;
		System.out.println("Your answer:");
		System.out.println("\t" + answer);
		System.out.println("Desired answer:");
		System.out.println("\t" + desiredAnswer);
		if (answer != desiredAnswer)
		{
			errors = true;
			System.out.println("DOESN'T MATCH!!!!");
		}
		else
			System.out.println("Match :-)");
		System.out.println();
		time = System.currentTimeMillis();
		answer = new DengklekMakingChains().maxBeauty(new String[]{"..1", "3..", "2..", ".7."});
		System.out.println("Time: " + (System.currentTimeMillis()-time)/1000.0 + " seconds");
		desiredAnswer = 7;
		System.out.println("Your answer:");
		System.out.println("\t" + answer);
		System.out.println("Desired answer:");
		System.out.println("\t" + desiredAnswer);
		if (answer != desiredAnswer)
		{
			errors = true;
			System.out.println("DOESN'T MATCH!!!!");
		}
		else
			System.out.println("Match :-)");
		System.out.println();
		time = System.currentTimeMillis();
		answer = new DengklekMakingChains().maxBeauty(new String[]{"412", "..7", ".58", "7.8", "32.", "6..", "351", "3.9", "985", "...", ".46"});
		System.out.println("Time: " + (System.currentTimeMillis()-time)/1000.0 + " seconds");
		desiredAnswer = 58;
		System.out.println("Your answer:");
		System.out.println("\t" + answer);
		System.out.println("Desired answer:");
		System.out.println("\t" + desiredAnswer);
		if (answer != desiredAnswer)
		{
			errors = true;
			System.out.println("DOESN'T MATCH!!!!");
		}
		else
			System.out.println("Match :-)");
		System.out.println();
		
		
		if (errors)
			System.out.println("Some of the test cases had errors :-(");
		else
			System.out.println("You're a stud (at least on the test data)! :-D ");
	}

}
// Powered by [KawigiEdit] 2.0!
